//
//  AXFMyCouponViewModel.m
//  AIXF
//
//  Created by mac on 2017/7/14.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "AXFMyCouponViewModel.h"
#import "AXFMineSever.h"
@implementation AXFMyCouponViewModel

IMPLEMENTATION_SINGLETON(AXFMyCouponViewModel);


+ (instancetype)shared
{
    static AXFMyCouponViewModel *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[AXFMyCouponViewModel alloc] init];
    });
    return instance;
}


//发送网络请求
-(NSArray<AXFMyCouponViewModel *> *)couponViewModel{
    
    if (!_couponViewModel) {
        //发起网络通知
        [self requesCouponData];
       // _couponViewModel = [self requesCouponData];
    }
    
    return _couponViewModel;
    
}


-(NSArray<AXFMyCouponViewModel*>*)requesCouponData{
    
    __block NSMutableArray *tempArrM = [NSMutableArray array];
    
    //发送网络请求对象
    AXFMineSever *mineSever = [AXFMineSever new];
    
    //发送网络请求
    [mineSever  requestMineMyCouponWith:^(id response) {
        NSArray *modelArr = [NSArray yy_modelArrayWithClass:[AXFMyCouponModel class] json:response];
        
        self.couponViewModel = modelArr;
        
        tempArrM = [modelArr mutableCopy];
        //遍历数组,创建viewModel
        //创建viewModel
//        for (AXFMyCouponModel *model in modelArr) {
//            
//            AXFMyCouponViewModel *viewModel = [AXFMyCouponViewModel new];
//            
//            viewModel.couponModel = model;
//            
//            [tempArrM addObject:viewModel];
//            
//        }
        
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"postData" object:nil];
    } andFailBlock:^(NSError *error) {
      
        NSLog(@"error:%@",error);
    }];
    return tempArrM;
    
}

@end
